import java.util.ArrayList;
import java.util.Scanner;

public class 学生管理系统 {
    public static void main(String[] args) {
        ArrayList<Student> arr = new ArrayList<Student>() {};
        boolean i = true;
        while(i) {
            System.out.println("-------欢迎来到学生管理系统-------");
            System.out.println("你想要做什么");
            System.out.println("1.添加学生");
            System.out.println("2.删除学生");
            System.out.println("3.修改学生");
            System.out.println("4.查看学生");
            System.out.println("5.退出");
            System.out.print("请选择：");
            int a=new Scanner(System.in).nextInt();
        switch(a){
            case 1:tianjia(arr);break;
            case 2:shanchu(arr);break;
            case 3:xiugai(arr);break;
            case 4:chakan(arr);break;
            case 5:i=false;break;
        }
        }
        System.out.println("谢谢使用");
    }


    //添加学生
    public static void tianjia(ArrayList<Student> arr) {
        //添加学号
        Student a = new Student();
        System.out.println("请输入学号：");
        Scanner sc = new Scanner(System.in);
        a.setXuehao(sc.nextLine());
        System.out.println("请输入姓名：");
        Scanner sc1 = new Scanner(System.in);
        a.setName(sc1.nextLine());
        System.out.println("请输入年龄：");
        Scanner sc2 = new Scanner(System.in);
        a.setAge(sc2.nextLine());
        System.out.println("请输入地址：");
        Scanner sc3 = new Scanner(System.in);
        a.setAddress(sc3.nextLine());
        arr.add(a);
    }

    //删除学生
    public static void shanchu(ArrayList<Student> arr) {
        System.out.println("请输入你要删除的学生的学号");
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        for (int i = 0; i < arr.size(); i++) {
            Student a = arr.get(i);
            if ((a.getXuehao().equals(s))) {
                arr.remove(i);
                System.out.println("已成功删除");
                break;
            } else if (i == arr.size() - 1 && !a.getXuehao().equals(s)) {
                System.out.println("你输入的学生不存在");
            }
        }
    }

    //修改学生
    public static void xiugai(ArrayList<Student> arr) {
        System.out.println("请输入要修改学生的学号：");
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        for (int i = 0; i < arr.size(); i++) {
            Student a = arr.get(i);
            if (a.getXuehao().equals(s)) {
                System.out.println("输入学生的新姓名：");
                Scanner sc1 = new Scanner(System.in);
                a.setName(sc1.nextLine());
                System.out.println("请输入新年龄：");
                Scanner sc2 = new Scanner(System.in);
                a.setAge(sc2.nextLine());
                System.out.println("请输入新地址：");
                Scanner sc3 = new Scanner(System.in);
                a.setAddress(sc3.nextLine());
                arr.set(i, a);
                break;
            }
        }
    }

    //查看学生信息
    public static void chakan(ArrayList<Student> arr) {
        System.out.println("学号        姓名        年龄       地址");
        for (int i = 0; i < arr.size(); i++) {
            Student a = arr.get(i);
            System.out.println(a.getXuehao()+"          "+a.getName()+"          "+a.getAge()+"          "+a.getAddress());
        }
    }
}
